Imports cmplib01
Imports System.Drawing.Drawing2D

Public Class ctlCreateUnit
    Inherits System.Windows.Forms.UserControl

    Public Event PointValueChange(ByVal newval As Integer)

    Private ptrUnit As ChitUnitTypeMember
    Private ptrCurrentGame As CampaignerGameData
    Private m_SelectedUnitType As UnitType

    Private m_BiggestSize As Integer
    Private m_FastestSpeed As Integer
    Private m_BiggestZOC As Integer

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlCreateUnit As System.Windows.Forms.Panel
    Friend WithEvents tvwUnitTypes As System.Windows.Forms.TreeView
    Friend WithEvents lblElementsHeader As System.Windows.Forms.Label
    Friend WithEvents tvwElements As System.Windows.Forms.TreeView
    Friend WithEvents chkUseElementPV As System.Windows.Forms.CheckBox
    Friend WithEvents numUnitPointValue As System.Windows.Forms.NumericUpDown
    Friend WithEvents Label11 As System.Windows.Forms.Label
    Friend WithEvents txtCreatedUnitName As System.Windows.Forms.TextBox
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents txtUnitTypeDescription As System.Windows.Forms.TextBox
    Friend WithEvents pnlIcons As System.Windows.Forms.Panel
    Friend WithEvents lblClickitbaby As System.Windows.Forms.Label
    Friend WithEvents lblFriendly As System.Windows.Forms.Label
    Friend WithEvents lblEnemy As System.Windows.Forms.Label
    Friend WithEvents lblOwner As System.Windows.Forms.Label
    Friend WithEvents picFriendly As System.Windows.Forms.PictureBox
    Friend WithEvents picEnemy As System.Windows.Forms.PictureBox
    Friend WithEvents picOwner As System.Windows.Forms.PictureBox
    Friend WithEvents lblSelectUnittype As System.Windows.Forms.Label
    Friend WithEvents imlUnitIcons As System.Windows.Forms.ImageList
    Friend WithEvents btnEditElements As System.Windows.Forms.Button
    Friend WithEvents lblPointValue As System.Windows.Forms.Label
    Friend WithEvents imlElement As System.Windows.Forms.ImageList
    Friend WithEvents pnlStatistics As System.Windows.Forms.Panel
    Friend WithEvents picSpeed As System.Windows.Forms.PictureBox
    Friend WithEvents picSize As System.Windows.Forms.PictureBox
    Friend WithEvents picZOC As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ctlCreateUnit))
        Me.pnlCreateUnit = New System.Windows.Forms.Panel
        Me.lblPointValue = New System.Windows.Forms.Label
        Me.btnEditElements = New System.Windows.Forms.Button
        Me.tvwUnitTypes = New System.Windows.Forms.TreeView
        Me.imlUnitIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.lblElementsHeader = New System.Windows.Forms.Label
        Me.tvwElements = New System.Windows.Forms.TreeView
        Me.imlElement = New System.Windows.Forms.ImageList(Me.components)
        Me.chkUseElementPV = New System.Windows.Forms.CheckBox
        Me.numUnitPointValue = New System.Windows.Forms.NumericUpDown
        Me.Label11 = New System.Windows.Forms.Label
        Me.txtCreatedUnitName = New System.Windows.Forms.TextBox
        Me.Label9 = New System.Windows.Forms.Label
        Me.txtUnitTypeDescription = New System.Windows.Forms.TextBox
        Me.pnlIcons = New System.Windows.Forms.Panel
        Me.lblClickitbaby = New System.Windows.Forms.Label
        Me.lblFriendly = New System.Windows.Forms.Label
        Me.lblEnemy = New System.Windows.Forms.Label
        Me.lblOwner = New System.Windows.Forms.Label
        Me.picFriendly = New System.Windows.Forms.PictureBox
        Me.picEnemy = New System.Windows.Forms.PictureBox
        Me.picOwner = New System.Windows.Forms.PictureBox
        Me.lblSelectUnittype = New System.Windows.Forms.Label
        Me.pnlStatistics = New System.Windows.Forms.Panel
        Me.picSpeed = New System.Windows.Forms.PictureBox
        Me.picSize = New System.Windows.Forms.PictureBox
        Me.picZOC = New System.Windows.Forms.PictureBox
        Me.pnlCreateUnit.SuspendLayout()
        CType(Me.numUnitPointValue, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.pnlIcons.SuspendLayout()
        Me.pnlStatistics.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlCreateUnit
        '
        Me.pnlCreateUnit.BackColor = System.Drawing.Color.LightSkyBlue
        Me.pnlCreateUnit.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlCreateUnit.Controls.Add(Me.pnlStatistics)
        Me.pnlCreateUnit.Controls.Add(Me.lblPointValue)
        Me.pnlCreateUnit.Controls.Add(Me.btnEditElements)
        Me.pnlCreateUnit.Controls.Add(Me.tvwUnitTypes)
        Me.pnlCreateUnit.Controls.Add(Me.lblElementsHeader)
        Me.pnlCreateUnit.Controls.Add(Me.tvwElements)
        Me.pnlCreateUnit.Controls.Add(Me.chkUseElementPV)
        Me.pnlCreateUnit.Controls.Add(Me.numUnitPointValue)
        Me.pnlCreateUnit.Controls.Add(Me.Label11)
        Me.pnlCreateUnit.Controls.Add(Me.txtCreatedUnitName)
        Me.pnlCreateUnit.Controls.Add(Me.Label9)
        Me.pnlCreateUnit.Controls.Add(Me.txtUnitTypeDescription)
        Me.pnlCreateUnit.Controls.Add(Me.pnlIcons)
        Me.pnlCreateUnit.Controls.Add(Me.lblSelectUnittype)
        Me.pnlCreateUnit.Dock = System.Windows.Forms.DockStyle.Fill
        Me.pnlCreateUnit.Location = New System.Drawing.Point(0, 0)
        Me.pnlCreateUnit.Name = "pnlCreateUnit"
        Me.pnlCreateUnit.Size = New System.Drawing.Size(528, 392)
        Me.pnlCreateUnit.TabIndex = 23
        '
        'lblPointValue
        '
        Me.lblPointValue.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblPointValue.BackColor = System.Drawing.Color.White
        Me.lblPointValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblPointValue.Location = New System.Drawing.Point(312, 33)
        Me.lblPointValue.Name = "lblPointValue"
        Me.lblPointValue.Size = New System.Drawing.Size(120, 21)
        Me.lblPointValue.TabIndex = 41
        Me.lblPointValue.Text = "0"
        Me.lblPointValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        Me.lblPointValue.Visible = False
        '
        'btnEditElements
        '
        Me.btnEditElements.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnEditElements.BackColor = System.Drawing.Color.LightSteelBlue
        Me.btnEditElements.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnEditElements.Location = New System.Drawing.Point(432, 72)
        Me.btnEditElements.Name = "btnEditElements"
        Me.btnEditElements.Size = New System.Drawing.Size(88, 23)
        Me.btnEditElements.TabIndex = 40
        Me.btnEditElements.Text = "Edit Elements"
        '
        'tvwUnitTypes
        '
        Me.tvwUnitTypes.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.tvwUnitTypes.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tvwUnitTypes.ImageList = Me.imlUnitIcons
        Me.tvwUnitTypes.Location = New System.Drawing.Point(8, 72)
        Me.tvwUnitTypes.Name = "tvwUnitTypes"
        Me.tvwUnitTypes.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Infantry Platoon"), New System.Windows.Forms.TreeNode("Armored Fist Squad"), New System.Windows.Forms.TreeNode("Stormtrooper Squad")})
        Me.tvwUnitTypes.ShowLines = False
        Me.tvwUnitTypes.ShowPlusMinus = False
        Me.tvwUnitTypes.ShowRootLines = False
        Me.tvwUnitTypes.Size = New System.Drawing.Size(176, 161)
        Me.tvwUnitTypes.TabIndex = 39
        '
        'imlUnitIcons
        '
        Me.imlUnitIcons.ImageSize = New System.Drawing.Size(16, 16)
        Me.imlUnitIcons.TransparentColor = System.Drawing.Color.Transparent
        '
        'lblElementsHeader
        '
        Me.lblElementsHeader.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblElementsHeader.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.lblElementsHeader.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblElementsHeader.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblElementsHeader.Location = New System.Drawing.Point(216, 96)
        Me.lblElementsHeader.Name = "lblElementsHeader"
        Me.lblElementsHeader.Size = New System.Drawing.Size(304, 17)
        Me.lblElementsHeader.TabIndex = 38
        Me.lblElementsHeader.Text = "Elements"
        '
        'tvwElements
        '
        Me.tvwElements.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.tvwElements.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.tvwElements.ImageList = Me.imlElement
        Me.tvwElements.Location = New System.Drawing.Point(216, 112)
        Me.tvwElements.Name = "tvwElements"
        Me.tvwElements.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Platoon HQ", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node12")}), New System.Windows.Forms.TreeNode("1st Squad", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("8x Guardsmen"), New System.Windows.Forms.TreeNode("1x Guardsman (LasCannon)"), New System.Windows.Forms.TreeNode("1x Guardsman (Meltagun)")}), New System.Windows.Forms.TreeNode("2nd Squad", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("1x Veteran Sergeant"), New System.Windows.Forms.TreeNode("7x Guardsmen"), New System.Windows.Forms.TreeNode("1x Guardsman (Autocannon)"), New System.Windows.Forms.TreeNode("1x Guardsman (Flamer)")}), New System.Windows.Forms.TreeNode("3rd Squad", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node11")})})
        Me.tvwElements.Size = New System.Drawing.Size(304, 192)
        Me.tvwElements.TabIndex = 37
        '
        'imlElement
        '
        Me.imlElement.ImageSize = New System.Drawing.Size(16, 16)
        Me.imlElement.ImageStream = CType(resources.GetObject("imlElement.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlElement.TransparentColor = System.Drawing.Color.Transparent
        '
        'chkUseElementPV
        '
        Me.chkUseElementPV.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.chkUseElementPV.CheckAlign = System.Drawing.ContentAlignment.MiddleRight
        Me.chkUseElementPV.Location = New System.Drawing.Point(216, 72)
        Me.chkUseElementPV.Name = "chkUseElementPV"
        Me.chkUseElementPV.Size = New System.Drawing.Size(136, 24)
        Me.chkUseElementPV.TabIndex = 36
        Me.chkUseElementPV.Text = "Use Elements PV"
        '
        'numUnitPointValue
        '
        Me.numUnitPointValue.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.numUnitPointValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numUnitPointValue.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.numUnitPointValue.Location = New System.Drawing.Point(312, 33)
        Me.numUnitPointValue.Maximum = New Decimal(New Integer() {32000, 0, 0, 0})
        Me.numUnitPointValue.Name = "numUnitPointValue"
        Me.numUnitPointValue.TabIndex = 35
        Me.numUnitPointValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'Label11
        '
        Me.Label11.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Label11.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label11.Location = New System.Drawing.Point(216, 36)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(104, 24)
        Me.Label11.TabIndex = 34
        Me.Label11.Text = "Unit Point Value"
        '
        'txtCreatedUnitName
        '
        Me.txtCreatedUnitName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtCreatedUnitName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtCreatedUnitName.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.txtCreatedUnitName.Location = New System.Drawing.Point(8, 32)
        Me.txtCreatedUnitName.Name = "txtCreatedUnitName"
        Me.txtCreatedUnitName.Size = New System.Drawing.Size(176, 22)
        Me.txtCreatedUnitName.TabIndex = 32
        Me.txtCreatedUnitName.Text = ""
        '
        'Label9
        '
        Me.Label9.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label9.Location = New System.Drawing.Point(8, 8)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(136, 24)
        Me.Label9.TabIndex = 31
        Me.Label9.Text = "Unit Name"
        '
        'txtUnitTypeDescription
        '
        Me.txtUnitTypeDescription.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtUnitTypeDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtUnitTypeDescription.Location = New System.Drawing.Point(8, 232)
        Me.txtUnitTypeDescription.Multiline = True
        Me.txtUnitTypeDescription.Name = "txtUnitTypeDescription"
        Me.txtUnitTypeDescription.Size = New System.Drawing.Size(176, 72)
        Me.txtUnitTypeDescription.TabIndex = 29
        Me.txtUnitTypeDescription.Text = "Unit Description goes in this window. Changes when a new unit is selected... duh." & _
        ""
        '
        'pnlIcons
        '
        Me.pnlIcons.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlIcons.BackColor = System.Drawing.Color.PowderBlue
        Me.pnlIcons.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlIcons.Controls.Add(Me.lblClickitbaby)
        Me.pnlIcons.Controls.Add(Me.lblFriendly)
        Me.pnlIcons.Controls.Add(Me.lblEnemy)
        Me.pnlIcons.Controls.Add(Me.lblOwner)
        Me.pnlIcons.Controls.Add(Me.picFriendly)
        Me.pnlIcons.Controls.Add(Me.picEnemy)
        Me.pnlIcons.Controls.Add(Me.picOwner)
        Me.pnlIcons.Location = New System.Drawing.Point(216, 312)
        Me.pnlIcons.Name = "pnlIcons"
        Me.pnlIcons.Size = New System.Drawing.Size(304, 72)
        Me.pnlIcons.TabIndex = 28
        '
        'lblClickitbaby
        '
        Me.lblClickitbaby.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblClickitbaby.Location = New System.Drawing.Point(4, 55)
        Me.lblClickitbaby.Name = "lblClickitbaby"
        Me.lblClickitbaby.Size = New System.Drawing.Size(208, 16)
        Me.lblClickitbaby.TabIndex = 15
        Me.lblClickitbaby.Text = "Click on an icon to change its image."
        '
        'lblFriendly
        '
        Me.lblFriendly.Location = New System.Drawing.Point(152, 2)
        Me.lblFriendly.Name = "lblFriendly"
        Me.lblFriendly.Size = New System.Drawing.Size(56, 16)
        Me.lblFriendly.TabIndex = 14
        Me.lblFriendly.Text = "Friendly"
        Me.lblFriendly.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblEnemy
        '
        Me.lblEnemy.Location = New System.Drawing.Point(84, 2)
        Me.lblEnemy.Name = "lblEnemy"
        Me.lblEnemy.Size = New System.Drawing.Size(48, 17)
        Me.lblEnemy.TabIndex = 13
        Me.lblEnemy.Text = "Enemy"
        Me.lblEnemy.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblOwner
        '
        Me.lblOwner.Location = New System.Drawing.Point(12, 2)
        Me.lblOwner.Name = "lblOwner"
        Me.lblOwner.Size = New System.Drawing.Size(48, 16)
        Me.lblOwner.TabIndex = 12
        Me.lblOwner.Text = "Owner"
        Me.lblOwner.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'picFriendly
        '
        Me.picFriendly.BackColor = System.Drawing.Color.Black
        Me.picFriendly.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picFriendly.Location = New System.Drawing.Point(162, 21)
        Me.picFriendly.Name = "picFriendly"
        Me.picFriendly.Size = New System.Drawing.Size(33, 33)
        Me.picFriendly.TabIndex = 11
        Me.picFriendly.TabStop = False
        '
        'picEnemy
        '
        Me.picEnemy.BackColor = System.Drawing.Color.Black
        Me.picEnemy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picEnemy.Location = New System.Drawing.Point(90, 21)
        Me.picEnemy.Name = "picEnemy"
        Me.picEnemy.Size = New System.Drawing.Size(33, 33)
        Me.picEnemy.TabIndex = 10
        Me.picEnemy.TabStop = False
        '
        'picOwner
        '
        Me.picOwner.BackColor = System.Drawing.Color.Black
        Me.picOwner.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picOwner.Location = New System.Drawing.Point(18, 21)
        Me.picOwner.Name = "picOwner"
        Me.picOwner.Size = New System.Drawing.Size(33, 33)
        Me.picOwner.TabIndex = 9
        Me.picOwner.TabStop = False
        '
        'lblSelectUnittype
        '
        Me.lblSelectUnittype.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblSelectUnittype.Location = New System.Drawing.Point(8, 56)
        Me.lblSelectUnittype.Name = "lblSelectUnittype"
        Me.lblSelectUnittype.Size = New System.Drawing.Size(184, 24)
        Me.lblSelectUnittype.TabIndex = 33
        Me.lblSelectUnittype.Text = "Select a unit type to deploy"
        '
        'pnlStatistics
        '
        Me.pnlStatistics.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pnlStatistics.BackColor = System.Drawing.Color.PowderBlue
        Me.pnlStatistics.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlStatistics.Controls.Add(Me.picZOC)
        Me.pnlStatistics.Controls.Add(Me.picSize)
        Me.pnlStatistics.Controls.Add(Me.picSpeed)
        Me.pnlStatistics.Location = New System.Drawing.Point(8, 312)
        Me.pnlStatistics.Name = "pnlStatistics"
        Me.pnlStatistics.Size = New System.Drawing.Size(176, 72)
        Me.pnlStatistics.TabIndex = 42
        '
        'picSpeed
        '
        Me.picSpeed.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picSpeed.BackColor = System.Drawing.Color.Gray
        Me.picSpeed.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picSpeed.Location = New System.Drawing.Point(8, 8)
        Me.picSpeed.Name = "picSpeed"
        Me.picSpeed.Size = New System.Drawing.Size(160, 18)
        Me.picSpeed.TabIndex = 0
        Me.picSpeed.TabStop = False
        '
        'picSize
        '
        Me.picSize.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picSize.BackColor = System.Drawing.Color.Gray
        Me.picSize.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picSize.Location = New System.Drawing.Point(8, 28)
        Me.picSize.Name = "picSize"
        Me.picSize.Size = New System.Drawing.Size(160, 18)
        Me.picSize.TabIndex = 1
        Me.picSize.TabStop = False
        '
        'picZOC
        '
        Me.picZOC.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picZOC.BackColor = System.Drawing.Color.Gray
        Me.picZOC.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picZOC.Location = New System.Drawing.Point(8, 49)
        Me.picZOC.Name = "picZOC"
        Me.picZOC.Size = New System.Drawing.Size(160, 18)
        Me.picZOC.TabIndex = 2
        Me.picZOC.TabStop = False
        '
        'ctlCreateUnit
        '
        Me.Controls.Add(Me.pnlCreateUnit)
        Me.Name = "ctlCreateUnit"
        Me.Size = New System.Drawing.Size(528, 392)
        Me.pnlCreateUnit.ResumeLayout(False)
        CType(Me.numUnitPointValue, System.ComponentModel.ISupportInitialize).EndInit()
        Me.pnlIcons.ResumeLayout(False)
        Me.pnlStatistics.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Property Unit() As ChitUnitTypeMember
        Get
            'Return ptrUnit
        End Get
        Set(ByVal Value As ChitUnitTypeMember)
            'ptrUnit = Value
            'Populate()
        End Set
    End Property

    Public WriteOnly Property CurrentGame() As CampaignerGameData
        Set(ByVal Value As CampaignerGameData)
            ptrCurrentGame = Value
        End Set
    End Property

    Private Sub Populate()
        If ptrUnit Is Nothing Then Exit Sub

        '// populate unittypes
        PopulateUnitTypes()

        txtCreatedUnitName.Text = ptrUnit.Name
        'numUnitPointValue.Value = ptrUnit.InitialPointValue

        'If ptrUnit.UseElementsForPointValue = True Then
        'chkUseElementPV.Checked = True
        'Else
        'chkUseElementPV.Checked = False
        'End If

        ListElements()
        ShowIcons()
    End Sub

    Private Sub PopulateUnitTypes()
        'Dim key As String
        Dim unit As UnitType
        Dim index As Int16

        tvwUnitTypes.Nodes.Clear()

        For Each unit In ptrCurrentGame.UnitTypes
            ' add the unit's icon to the imagelist
            imlUnitIcons.Images.Add(unit.Icon(cmplib01.IconImageIndex_cgd.Owner))
            Dim nodUnit As New TreeNode

            If unit.Size > m_BiggestSize Then m_BiggestSize = unit.Size
            If unit.MovementSpeed > m_FastestSpeed Then m_FastestSpeed = unit.MovementSpeed
            If unit.ZOCRange > m_BiggestZOC Then m_BiggestZOC = unit.ZOCRange

            nodUnit.Text = unit.TypeName
            nodUnit.Tag = unit.Key
            nodUnit.ImageIndex = index
            nodUnit.SelectedImageIndex = index
            tvwUnitTypes.Nodes.Add(nodUnit)
            index += 1
        Next

        tvwUnitTypes.Sort()

    End Sub

    Private Sub ListElements()
        tvwElements.Nodes.Clear()

        Try
            tvwElements.Nodes.Clear()

            ''// first list the chit name
            'Dim nod As New TreeNode(ptrUnit.Name)
            'nod.ImageIndex = 3 '// this is the special place. :)
            'nod.SelectedImageIndex = 3

            'tvwElements.Nodes.Add(nod)

            ''// and add the group sub nodes
            'Dim group As ElementGroup
            'Dim EleGroup As GroupableElements = ptrUnit.Elements

            'Dim opt As ElementOption

            'For Each group In EleGroup.Groups
            '    Dim GroupNode As New TreeNode(group.GroupName)
            '    GroupNode.ImageIndex = 0
            '    GroupNode.SelectedImageIndex = 0
            '    nod.Nodes.Add(GroupNode)
            '    GroupNode.EnsureVisible()
            'Next

            'Dim ele As GroupableElement

            ''// first post the Non-grouped elements
            'For Each ele In EleGroup
            '    If ele.GroupName = "<Ungrouped>" Then
            '        Dim NoGroup As New TreeNode(ele.Count & "x " & ele.ElementTypeName & " (" & ele.TotalCost & ")")

            '        For Each opt In ele.Options
            '            Dim optNode As New TreeNode
            '            optNode.Text = opt.ElementOptionTypeName & " (" & opt.ElementOptionPointCost & ")"
            '            optNode.SelectedImageIndex = 2
            '            optNode.ImageIndex = 2
            '            NoGroup.Nodes.Add(optNode)
            '        Next

            '        NoGroup.ImageIndex = 1
            '        NoGroup.SelectedImageIndex = 1
            '        nod.Nodes.Add(NoGroup)
            '    End If
            'Next

            ''// now go through all of the elements and find the group it belongs to
            'For Each ele In EleGroup
            '    Dim nodie As TreeNode
            '    For Each nodie In nod.Nodes
            '        If ele.GroupName = nodie.Text Then

            '            Dim eleNode As New TreeNode(ele.Count & "x " & ele.ElementTypeName & " (" & ele.TotalCost & ")")

            '            For Each opt In ele.Options
            '                Dim optNode As New TreeNode
            '                optnode.Text = opt.ElementOptionTypeName & " (" & opt.ElementOptionPointCost & ")"
            '                optnode.SelectedImageIndex = 2
            '                optnode.ImageIndex = 2
            '                eleNode.Nodes.Add(optnode)
            '            Next

            '            eleNode.ImageIndex = 1
            '            eleNode.SelectedImageIndex = 1
            '            nodie.Nodes.Add(eleNode)
            '            eleNode.EnsureVisible()
            '        End If
            '    Next
            'Next
        Catch ex As Exception
            HandleException("frmChitTreeHierarchy.BuildTree", ex)
        End Try

    End Sub

    Private Sub ShowIcons()
        picOwner.BackgroundImage = ptrUnit.icon
        picEnemy.BackgroundImage = ptrUnit.icon
        picFriendly.BackgroundImage = ptrUnit.icon

    End Sub

    Private Sub tvwUnitTypes_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwUnitTypes.AfterSelect
        Dim selNode As TreeNode = e.Node
        Dim unit As UnitType = ptrCurrentGame.UnitTypes.Item(selNode.Tag)

        txtUnitTypeDescription.Text = unit.Description

        ' set up the selected unit
        m_SelectedUnitType = unit

        ptrUnit.icon = unit.Icon(cmplib01.IconImageIndex_cgd.Owner)
        'ptrUnit.Icon(cmplib01.IconImageIndex_cgd.Enemy) = unit.Icon(cmplib01.IconImageIndex_cgd.Enemy)
        'ptrUnit.Icon(cmplib01.IconImageIndex_cgd.SameFaction) = unit.Icon(cmplib01.IconImageIndex_cgd.SameFaction)

        ' put this icon in the elements icon house, so it can be used for display. If there is already one there... DIE to it.
        If imlElement.Images.Count = 4 Then
            imlElement.Images.RemoveAt(3)
            imlElement.Images.Add(ptrUnit.icon)
        Else
            imlElement.Images.Add(ptrUnit.icon)
        End If

        tvwElements.Refresh()

        ' update rules
        'ptrUnit.GCRules = unit.GCRules.Clone

        'With ptrUnit
        '    .Description = unit.Description
        '    .GroundChitClass = unit.GroundChitClass
        '    .LOS = unit.LOS
        '    .LOSPower = unit.LOSPower
        '    .MovementClassID = unit.MovementClassID
        '    .MovementSpeed = unit.MovementSpeed
        '    .Size = unit.Size
        '    .TypeName = unit.TypeName
        '    .UsesZOC = unit.UsesZOC
        '    .ZOCRange = unit.ZOCRange
        '    .TransportCapacity = unit.TransportCapacity
        '    .TransportCost = unit.TransportCost
        '    .CanBeTransported = unit.CanBeTransported
        '    .CanTransport = unit.CanTransport
        'End With

        showSelectedStatistics()

        'bunitSelected = True
        ShowIcons()
    End Sub

    Private Sub showSelectedStatistics()
        Dim strength As Single
        Try
            strength = m_SelectedUnitType.MovementSpeed / m_FastestSpeed
            drawBar(strength, picSpeed, "Base Movement Speed")
            strength = m_SelectedUnitType.Size / m_BiggestSize
            drawBar(strength, picSize, "Size")
            strength = m_SelectedUnitType.ZOCRange / m_BiggestZOC
            drawBar(strength, picZOC, "Zone Of Control")
        Catch ex As Exception

        End Try

    End Sub

    Private Sub drawBar(ByVal strength As Single, ByVal target As PictureBox, ByVal text As String)

        Dim bar As New RectangleF(1, 1, (picSize.Width * strength) - 6, 14)

        Dim imCom As Image = New Bitmap(target.Width, target.Height)
        Dim g As Graphics = Graphics.FromImage(imCom)

        Dim br As New LinearGradientBrush(bar, Color.Red, Color.Green, LinearGradientMode.Horizontal)

        g.FillRectangle(br, bar)

        g.DrawString(text, Me.Font, New SolidBrush(Color.Yellow), 2, 2)

        target.Image = imCom

        g.Dispose()

    End Sub

    Private Sub btnEditElements_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditElements.Click

        'Dim f As New frmElementManager(ptrCurrentGame, ptrUnit)
        'f.ShowDialog()
        'ListElements()

        'If chkUseElementPV.Checked = True Then

        '    elementCost()

        'End If

    End Sub

    Private Sub txtCreatedUnitName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCreatedUnitName.TextChanged
        If ptrUnit Is Nothing Then Exit Sub

        If txtCreatedUnitName.Text.Length > 0 Then ptrUnit.Name = txtCreatedUnitName.Text

        If Not tvwElements.Nodes(0) Is Nothing Then
            tvwElements.Nodes(0).Text = txtCreatedUnitName.Text
        End If

    End Sub

    Private Sub chkUseElementPV_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUseElementPV.CheckedChanged
        'If chkUseElementPV.Checked = True Then
        '    elementCost()
        '    numUnitPointValue.Visible = False
        '    lblPointValue.Visible = True
        '    'lblPointValue.Text = ptrUnit.InitialPointValue
        'Else
        '    Unit.UseElementsForPointValue = False
        '    numUnitPointValue.Value = 0
        '    Unit.InitialPointValue = 0
        '    Unit.CurrentPointValue = 0
        '    lblPointValue.Visible = False
        '    numUnitPointValue.Visible = True
        'End If
    End Sub

    Private Sub elementCost()
        'Dim ele As Element
        'Dim opt As ElementOption

        'Dim optCost As Integer
        'Dim pv As Integer

        'For Each ele In ptrUnit.ChitElements
        '    optCost = 0
        '    For Each opt In ele.Options
        '        optCost += opt.ElementOptionPointCost
        '    Next
        '    pv += ((ele.ElementBaseCost + optCost) * ele.Count)
        'Next

        'Unit.UseElementsForPointValue = True
        'Unit.InitialPointValue = pv
        'Unit.CurrentPointValue = Unit.InitialPointValue
        'lblPointValue.Text = pv
        'RaiseEvent PointValueChange(pv)

    End Sub

    Private Sub numUnitPointValue_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numUnitPointValue.ValueChanged
        RaiseEvent PointValueChange(numUnitPointValue.Value)
        'Unit.InitialPointValue = numUnitPointValue.Value
        'Unit.CurrentPointValue = numUnitPointValue.Value
    End Sub

    Private Sub picIcon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picOwner.Click, picEnemy.Click, picFriendly.Click
        SetNewIcon(sender)

    End Sub

    Private Sub SetNewIcon(ByRef pic As PictureBox)
        '// sets the icon into the picture
        Try
            Dim fOpen As New OpenFileDialog
            fOpen.Filter = "Picture Files | *.bmp; *.jpg"
            fOpen.ShowDialog()

            pic.Image = Image.FromFile(fOpen.FileName)

            ' now we'll update all the images
            If Not ptrUnit Is Nothing Then
                ptrUnit.icon = picOwner.Image
                'ptrUnit.Icon(IconImageIndex_cgd.Enemy) = picEnemy.Image
                'ptrUnit.Icon(IconImageIndex_cgd.SameFaction) = picFriendly.Image
            End If

        Catch ex As Exception

        End Try

    End Sub

    Private Sub numUnitPointValue_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles numUnitPointValue.KeyUp
        RaiseEvent PointValueChange(numUnitPointValue.Value)
        'Unit.InitialPointValue = numUnitPointValue.Value
        'Unit.CurrentPointValue = numUnitPointValue.Value
    End Sub
End Class
